package cn.qzbook;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class MybatisTool {

    private static final SqlSessionFactory sqlSessionFactory;

    private MybatisTool(){}

    static {
        InputStream resourceAsStream = null;
        try {
            resourceAsStream = Resources.getResourceAsStream("configuration.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }

        SqlSessionFactoryBuilder sfb = new SqlSessionFactoryBuilder();

        sqlSessionFactory = sfb.build(resourceAsStream);

    }

    public static SqlSessionFactory sqlSessionFactory(){
        return sqlSessionFactory;
    }

}
